package com.example.springbootdemo.ext;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.stereotype.Component;

import java.util.Arrays;

@Component
public class MyBeanFactoryPostProcessor implements BeanFactoryPostProcessor {
    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
        System.out.println("MyBeanFactoryPostProcessor 的 postProcessBeanFactory");

        final int beanDefinitionCount = beanFactory.getBeanDefinitionCount();

        final String[] beanDefinitionNames = beanFactory.getBeanDefinitionNames();

        System.out.println("当前一共有" + beanDefinitionCount + "个 bean");
        System.out.println("bean 的名称分别为："+ Arrays.asList(beanDefinitionNames));
    }
}
